
Partial Class admin_appUserConfig
    Inherits System.Web.UI.Page

    Private Const _maxPasswordLength As Integer = 50
    Private Const _maxUserIdLength As Integer = 50

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.MessageLabel.Visible = False

    End Sub

    Protected Sub SubmitButton_Click(ByVal sender As Object, _
                                     ByVal e As System.EventArgs) _
                                     Handles SubmitButton.Click

        Me.MessageLabel.Text = ""

        Dim userConfig As Cdm.DataCore.LookupTables.LuPasswordConfiguration
        userConfig = Cdm.DataCore.LookupTables.LuPasswordConfiguration.Retrieve(CInt(Me.UserConfigFormView.DataKey.Value.ToString()))

        Dim PwdLengthTextBox As TextBox = CType(Me.UserConfigFormView.FindControl("PwdLengthTextBox"), TextBox)
        Dim UidLengthTextBox As TextBox = CType(Me.UserConfigFormView.FindControl("UidLengthTextBox"), TextBox)
        Dim AttemptsTextBox As TextBox = CType(Me.UserConfigFormView.FindControl("AttemptsTextBox"), TextBox)
        Dim ExpirationTextBox As TextBox = CType(Me.UserConfigFormView.FindControl("ExpirationTextBox"), TextBox)
        Dim InactivityTextBox As TextBox = CType(Me.UserConfigFormView.FindControl("InactivityTextBox"), TextBox)

        If IsNumeric(PwdLengthTextBox.Text) And _
           IsNumeric(UidLengthTextBox.Text) And _
           IsNumeric(AttemptsTextBox.Text) And _
           IsNumeric(ExpirationTextBox.Text) And _
           IsNumeric(InactivityTextBox.Text) Then

            If ((CInt(PwdLengthTextBox.Text) > 0 And CInt(PwdLengthTextBox.Text) <= _maxPasswordLength) And _
                (CInt(UidLengthTextBox.Text) > 0 And CInt(UidLengthTextBox.Text) <= _maxUserIdLength)) And _
                (CInt(ExpirationTextBox.Text) > 0) Then

                userConfig.PasswordLength = CInt(PwdLengthTextBox.Text)
                userConfig.UseridLength = CInt(UidLengthTextBox.Text)
                userConfig.LockOutAttempts = CInt(AttemptsTextBox.Text)
                userConfig.ExpirePeriod = CInt(ExpirationTextBox.Text)
                userConfig.InactivityPeriod = CInt(InactivityTextBox.Text)

                Cdm.DataCore.LookupTables.LuPasswordConfiguration.UpdateInstance(userConfig)

                Me.ShowMessage("Configuration information saved successfully.", Drawing.Color.Firebrick)

            Else

                If CInt(PwdLengthTextBox.Text) > _maxPasswordLength Then
                    Me.ShowMessage("Password length must be less than or equal to " & admin_appUserConfig._maxPasswordLength.ToString & " characters long.", Drawing.Color.Firebrick)
                End If
                If CInt(UidLengthTextBox.Text) > _maxUserIdLength Then
                    Me.ShowMessage("UserId length must be less than or equal to " & admin_appUserConfig._maxUserIdLength.ToString & " characters long.", Drawing.Color.Firebrick)
                End If
                If CInt(ExpirationTextBox.Text) < 0 Then
                    Me.ShowMessage("Expiration period must be greater than 0.", Drawing.Color.Firebrick)
                End If

            End If

        Else
            Me.ShowMessage("All values must be a number.", Drawing.Color.Firebrick)
        End If

    End Sub

    Protected Sub ShowMessage(ByVal message As String, ByVal foreColor As System.Drawing.Color)

        Me.MessageLabel.ForeColor = foreColor
        Me.MessageLabel.Visible = True
        Me.MessageLabel.Text &= message & "<br />"

    End Sub

End Class
